Python3如何实现Win10桌面自动切换

您所在的位置:网站首页 win10 切换python版本 Python3如何实现Win10桌面自动切换

Python3如何实现Win10桌面自动切换

#Python3如何实现Win10桌面自动切换| 来源: 网络整理| 查看: 265

得空写了个自动切换桌面背景图片的小程序。再不写python就要扔键盘了,对vue还有那么一点好感,天天php真是有够烦。

准备工作

准备个文件夹放在桌面上,平时看到什么高清好图就拽进去。

运行脚本

脚本如下:

#!/usr/bin/python import ctypes import osimport random import functools import schedule index = 0 def change_background(picture_path: str) -> None: ctypes.windll.user32.SystemParametersInfoW(20, 0, picture_path, 3) def get_pictures(dir_path: str) -> list: return [os.path.join(root, name) for root, dirs, files in os.walk(dir_path, topdown=False) for name in files if name.endswith('jpg') or name.endswith('png')] def log(text): def decorator(f): @functools.wraps(f) def wrap(*args, **kwargs): p = f(*args, **kwargs) print(f'{text}: {p}') return p return wrap return decorator @log(f'DESKTOP_BG_IMG switch to') def change_background_job(dir_path) -> None: if dir_path.__class__.__name__ == 'list': dir_path = dir_path[0] pictures = get_pictures(dir_path) index = random.randint(0, len(pictures) - 1) change_background(pictures[index]) return pictures[index] def scheduler(job: staticmethod, interval, arg_num, *args) -> None: if arg_num


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3